<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
            <el-form-item label="" prop="">
                <el-date-picker
                    v-model="rangeVal"
                    type="daterange"
                    value-format="timestamp"
                    range-separator="至"
                    start-placeholder="开始日期"
                    end-placeholder="结束日期">
                </el-date-picker>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
            <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>

        <el-table v-loading="loading" :data="goalList" row-key="id" default-expand-all :tree-props="{children: 'details'}">
            <el-table-column label="记录" align="center" prop="id" />
            <el-table-column label="耗时" align="center" >
                <template slot-scope="{row,$index}">
                    <template v-if="row.end">
                        {{ (row.end - row.start) / 1000 }}
                    </template>
                    <template v-else>
                        {{ (row.start - dataList[$index-1].start ) / 1000 }}
                    </template>
                </template>
            </el-table-column>
            <el-table-column label="目标" align="center" prop="goal" />
            <el-table-column label="规则" align="center" prop="rule" />
            <el-table-column label="prompt" align="center" prop="prompt" />
            <el-table-column label="话术" align="center" prop="verbalTrick" />
        </el-table>

        <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
            @pagination="getList" />

    
    </div>
</template>

<script>
import { listVerbal, getVerbal } from "@/api/goal/verbal";


export default {
    name: "Verbal",
    data() {
        return {
            // 遮罩层
            loading: true,
            // 选中数组
            ids: [],
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            goalList: [],
            dataList: [],
            rangeVal: [],
            // 是否显示弹出层
            open: false,
            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 10,
                start: null,
                end: null,
            },
        
        };
    },
    created() {
        this.getList();
    },
    methods: {
        getList() {
            this.loading = true;
            this.goalList = []
            this.dataList = []
            listVerbal(this.queryParams).then(response => {
                this.goalList = response.rows;
                response.rows.forEach(s => {
                    this.dataList.push(s)
                    s.details.forEach(d => {
                        d.start = d.date
                        this.dataList.push(d)
                    })
                })
                this.total = response.total;
                this.loading = false;
            });
        },
        /** 搜索按钮操作 */
        handleQuery() {
            if(this.rangeVal && this.rangeVal.length  == 2) {
                this.queryParams.start = this.rangeVal[0]
                this.queryParams.end = this.rangeVal[1] + 24*60*60*1000
            }
            this.queryParams.pageNum = 1;
            this.getList();
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.resetForm("queryForm");
            this.handleQuery();
        },
      
    }
};
</script>

<style lang="scss" scoped>
  /*左边工具栏以及编辑节点的样式*/
  @import '~bpmn-js/dist/assets/diagram-js.css';
  @import '~bpmn-js/dist/assets/bpmn-font/css/bpmn.css';
  @import '~bpmn-js/dist/assets/bpmn-font/css/bpmn-codes.css';
  @import '~bpmn-js/dist/assets/bpmn-font/css/bpmn-embedded.css';
  .containers{
    position: absolute;
    background-color: #ffffff;
    width: 100%;
    height: 100%;
    .canvas{
      width: 100%;
      height: 100%;
    }
    .bjs-powered-by {
      display: none;
    }
  }
</style>